package com.cal.utms.model.payment;

import java.math.BigDecimal;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Locale;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import com.cal.utms.action.user_maintenance.LoginAction;
import com.cal.utms.dao.maintenance.CustomerDaoImpl;
import com.cal.utms.dao.maintenance.NewFundDao;
import com.cal.utms.dao.payment.InvestmentDaoImpl;
import com.cal.utms.dao.payment.PledgeDaoImpl;
import com.cal.utms.dao.payment.RedemptionDaoImpl;
import com.cal.utms.dao.user_maintenance.UserDaoImpl;
import com.cal.utms.dto.payment.RedemptionDto;
import com.cal.utms.dto.payment.RedemptionInvestmentDto;
import com.cal.utms.dto.payment.SummaryDetailDto;
import com.cal.utms.entity.CustomerInvestment;
import com.cal.utms.entity.CustomerPledge;
import com.cal.utms.entity.CustomerRedemptionRequest;
import com.cal.utms.entity.CustomerTransactionLog;
import com.cal.utms.entity.MoneyTransaction;
import com.cal.utms.entity.RedemptionReqToRedemtion;
import com.cal.utms.util.NextDate;
import com.cal.utms.util.Sequence;

public class RedemptionModel {

	RedemptionDaoImpl daoImpl = new RedemptionDaoImpl();
	CustomerDaoImpl customerDaoImpl = new CustomerDaoImpl();
	UserDaoImpl userDaoImpl = new UserDaoImpl();
	NewFundDao fundDao = new NewFundDao();
	MoneyTransactionModel moneyTransactionModel = new MoneyTransactionModel();
	InvestmentDaoImpl investmentDaoImpl = new InvestmentDaoImpl();
	private PledgeDaoImpl pledgeDaoImpl = new PledgeDaoImpl();
	SimpleDateFormat format = new SimpleDateFormat("dd/MM/yyyy", Locale.ENGLISH);

	public List<RedemptionDto> getAllRequest() {
		List<RedemptionDto> dtos = new ArrayList<RedemptionDto>();
		List<CustomerRedemptionRequest> requests = daoImpl.getRedemptionRequest();
		for (CustomerRedemptionRequest customerRedemptionRequest : requests) {
			RedemptionDto dto = new RedemptionDto();
			dto.setId(customerRedemptionRequest.getId());
			dto.setCustomer(customerRedemptionRequest.getCustomer().getId());
			dto.setCustomer_name(customerRedemptionRequest.getCustomer().getDenotedByInitials() + " " + customerRedemptionRequest.getCustomer().getSurname());
			dto.setRedemptionCode(customerRedemptionRequest.getRedemptionCode());
			dto.setRedemptionType(customerRedemptionRequest.getRedemptionType());
			if (customerRedemptionRequest.getRequestDate() != null)
				dto.setRequestDate(format.format(customerRedemptionRequest.getRequestDate()));
			dto.setStatus(customerRedemptionRequest.getStatus());
			if (customerRedemptionRequest.getExpectedDate() != null)
				dto.setExpectedDate(format.format(customerRedemptionRequest.getExpectedDate()));
			dto.setFund_id(customerRedemptionRequest.getFund().getId());
			if (customerRedemptionRequest.getTotAmount() != null)
				dto.setTotAmount(customerRedemptionRequest.getTotAmount().toString());
			if (customerRedemptionRequest.getTotUnit() != null)
				dto.setTotUnit(customerRedemptionRequest.getTotUnit().toString());
			if (customerRedemptionRequest.getConfirmDate() != null)
				dto.setConfirmDate(format.format(customerRedemptionRequest.getConfirmDate()));
			dto.setRecordUser(customerRedemptionRequest.getRecordUser());
			// dto.setRedemptionReqToRedemtions(customerRedemptionRequest.getRedemptionReqToRedemtions());
			if (customerRedemptionRequest.getStatus().equals("CONFIRM")) {
				dto.setUnitprice(customerRedemptionRequest.getRedemUnitPrice().toString());
			}
			dto.setRecordType(customerRedemptionRequest.getRecordType());
			dtos.add(dto);
		}
		return dtos;
	}

	public List<RedemptionInvestmentDto> getRedemtion(int redemtion_id) {

		List<RedemptionReqToRedemtion> redemtions = daoImpl.getRedemtion(redemtion_id);
		List<RedemptionInvestmentDto> dtos = new ArrayList<RedemptionInvestmentDto>();
		for (RedemptionReqToRedemtion redemtion : redemtions) {
			RedemptionInvestmentDto dto = new RedemptionInvestmentDto();
			if (redemtion.getCustomerInvestment() != null) {
				dto.setInvenstmentCode(redemtion.getCustomerInvestment().getInvenstmentCode());
				dto.setInvestmentId(redemtion.getCustomerInvestment().getId());
				if (redemtion.getCustomerInvestment().getIssuedDate() != null)
					dto.setConfirmDate(format.format(redemtion.getCustomerInvestment().getIssuedDate()));
				dto.setAmount(redemtion.getCustomerInvestment().getAmount());
				dto.setNoOfUnits(redemtion.getCustomerInvestment().getNoOfIssuedUnit());

				if (redemtion.getCustomerRedemptionRequest().getRecordType().equals("M")) {
					BigDecimal issuedUnit = redemtion.getCustomerInvestment().getNoOfIssuedUnit();
					BigDecimal issuedUnitPrice = redemtion.getCustomerInvestment().getIssuedUnitPrice();
					BigDecimal currentUnitPrice = redemtion.getCustomerRedemptionRequest().getFund().getUnitValue();
					BigDecimal amount = issuedUnit.multiply(currentUnitPrice.subtract(issuedUnitPrice));
					if (amount.compareTo(BigDecimal.ZERO) == 1) {
						dto.setReleaseAmount(amount);
					}
				} else {
					dto.setReleaseAmount(redemtion.getReleaseAmount());
					dto.setReleaseUnits(redemtion.getReleaseUnits());
				}
				dto.setRemainingUnits(redemtion.getCustomerInvestment().getBalanceUnits());
			}
			if (redemtion.getCustomerRedemptionRequest().getStatus().equals("CONFIRM")) {
				dto.setUnitPrice(redemtion.getCustomerRedemptionRequest().getRedemUnitPrice());
			} else {
				dto.setUnitPrice(redemtion.getCustomerRedemptionRequest().getFund().getUnitValue());
			}
			dtos.add(dto);
		}
		return dtos;
	}

	public void saveRedemption(RedemptionDto redemptionDto, String redemDetails) {

		Sequence seq = new Sequence();
		CustomerRedemptionRequest request = new CustomerRedemptionRequest();
		request.setCustomer(customerDaoImpl.getCustomerById(redemptionDto.getCustomer()));
		request.setRedemptionCode("RED" + seq.getNextValue("REDEMPTION"));
		request.setRedemptionType(redemptionDto.getRedemptionType());
		try {
			if (redemptionDto.getRequestDate() != null)
				request.setRequestDate(format.parse(redemptionDto.getRequestDate()));
			if (redemptionDto.getExpectedDate() != null)
				request.setExpectedDate(format.parse(redemptionDto.getExpectedDate()));
		} catch (ParseException e) {
			e.printStackTrace();
		}
		request.setStatus(redemptionDto.getStatus());
		request.setFund(fundDao.getById(redemptionDto.getFund_id()));
		if (redemptionDto.getTotAmount() != null) {
			String amount = redemptionDto.getTotAmount().replaceAll(",", "");
			double da = Double.parseDouble(amount);
			request.setTotAmount(BigDecimal.valueOf(da));
		}
		if (redemptionDto.getTotUnit() != null) {
			String amount = redemptionDto.getTotUnit().replaceAll(",", "");
			double du = Double.parseDouble(amount);
			request.setTotUnit(BigDecimal.valueOf(du));
		}
		request.setRedemUnitPrice(BigDecimal.ZERO);
		request.setRecordType("O");
		request.setRecordUser(LoginAction.getCurrentLogingUser().getId());
		request.setRecordDate(new Date());

		List<RedemptionReqToRedemtion> redemptList = new ArrayList<RedemptionReqToRedemtion>();

		if (redemDetails != null) {
			redemDetails = "{ \"redemDetails\" : ".concat(redemDetails) + " }";
			try {
				JSONObject jsonObject = new JSONObject(redemDetails);
				JSONArray jArray = jsonObject.getJSONArray("redemDetails");
				for (int i = 0; i < jArray.length(); i++) {
					JSONObject jObj = jArray.getJSONObject(i);
					RedemptionReqToRedemtion redemtion = new RedemptionReqToRedemtion();
					redemtion.setCustomerInvestment(investmentDaoImpl.getById(jObj.getInt("investmentId")));
					redemtion.setCustomerRedemptionRequest(request);
					redemtion.setBalance(BigDecimal.ZERO);
					redemtion.setReleaseAmount(BigDecimal.valueOf(jObj.getDouble("releaseAmount")));
					redemtion.setReleaseUnits(BigDecimal.valueOf(jObj.getDouble("releaseUnits")));
					redemptList.add(redemtion);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		request.setRedemptionReqToRedemtions(redemptList);

		Object object = daoImpl.saveRedemtioRequest(request);
		if (object instanceof Integer) {
			redemptionDto.setId((Integer) object);
			redemptionDto.setSuccess(true);
			redemptionDto.setResulteMsg("SUCCESS");
		} else {
			redemptionDto.setSuccess(false);
			redemptionDto.setResulteMsg("There is some error returned from the server.");
		}

	}

	public void confirmRedemption(RedemptionDto redemptionDto, int redemption_id) {

		List<CustomerInvestment> customerInvestments = checkInvestmentBalance(daoImpl.getRedemtion(redemption_id));
		CustomerRedemptionRequest monthlyRedempRequest = null;
		CustomerInvestment customerInvestment = null;
		if (customerInvestments.size() > 0) {
			CustomerRedemptionRequest customerRedemptionRequest = daoImpl.getById(redemption_id);

			/* Create next redemption request */
			if (customerRedemptionRequest.getRecordType().equals("M")) {
				NextDate nextDate = new NextDate();

				customerInvestment = customerRedemptionRequest.getRedemptionReqToRedemtions().get(0).getCustomerInvestment();
				if (customerInvestment.getMonthlyInterestRequired() == 1) {
					try {
						customerInvestment.setMonIntLastPaidDate(format.parse(redemptionDto.getConfirmDate()));
						customerInvestment.setMonIntNextDate(nextDate.getNextDate(customerRedemptionRequest.getExpectedDate(), customerInvestment.getInterestType()));
						monthlyRedempRequest = createNextMonthlyRedemtioReqest(customerInvestment);
					} catch (ParseException e) {
						e.printStackTrace();
					}
				}
			}

			try {
				customerRedemptionRequest.setConfirmDate(format.parse(redemptionDto.getConfirmDate()));
			} catch (ParseException e) {
				e.printStackTrace();
			}
			if (redemptionDto.getUnitprice() != null) {
				String amount = redemptionDto.getUnitprice().replaceAll(",", "");
				double da = Double.parseDouble(amount);
				customerRedemptionRequest.setRedemUnitPrice(BigDecimal.valueOf(da));
			}
			customerRedemptionRequest.setStatus("CONFIRM");
			customerRedemptionRequest.setConfirmUser(LoginAction.getCurrentLogingUser().getId());

			/* Create Transactionlogs */
			List<CustomerTransactionLog> customerTransactionLogs = createLogs(customerRedemptionRequest.getRedemptionReqToRedemtions(), customerRedemptionRequest);

			/* Create Money Transaction record */
			List<MoneyTransaction> moneyTransactions = moneyTransactionModel.getRedemptionTransaction(customerRedemptionRequest, redemptionDto, redemption_id);

			if (customerRedemptionRequest.getTotAmount() != null) {
				if (!redemptionDto.getTotAmount().replaceAll(",", "").equals(customerRedemptionRequest.getTotAmount().toString())) {
					redemptionDto.setSuccess(false);
					redemptionDto.setResulteMsg("There is some error returned from the server.");
					return;
				} else {
					if (redemptionDto.getTotAmount() != null) {
						String amount = redemptionDto.getTotAmount().replaceAll(",", "");
						double da = Double.parseDouble(amount);
						customerRedemptionRequest.setTotAmount(BigDecimal.valueOf(da));
					}
					if (redemptionDto.getTotUnit() != null) {
						String amount = redemptionDto.getTotUnit().replaceAll(",", "");
						double da = Double.parseDouble(amount);
						customerRedemptionRequest.setTotUnit(BigDecimal.valueOf(da));
					}
					daoImpl.confirm(customerRedemptionRequest, moneyTransactions, customerInvestments, customerTransactionLogs, monthlyRedempRequest, customerInvestment);
					redemptionDto.setSuccess(true);
					redemptionDto.setResulteMsg("SUCCESS");

				}
			} else if (customerRedemptionRequest.getTotUnit() != null) {
				if (!redemptionDto.getTotUnit().replaceAll(",", "").equals(customerRedemptionRequest.getTotUnit().toString())) {
					redemptionDto.setSuccess(false);
					redemptionDto.setResulteMsg("There is some error returned from the server.");
					return;
				} else {
					if (redemptionDto.getTotAmount() != null) {
						String amount = redemptionDto.getTotAmount().replaceAll(",", "");
						double da = Double.parseDouble(amount);
						customerRedemptionRequest.setTotAmount(BigDecimal.valueOf(da));
					}
					if (redemptionDto.getTotUnit() != null) {
						String amount = redemptionDto.getTotUnit().replaceAll(",", "");
						double da = Double.parseDouble(amount);
						customerRedemptionRequest.setTotUnit(BigDecimal.valueOf(da));
					}
					daoImpl.confirm(customerRedemptionRequest, moneyTransactions, customerInvestments, customerTransactionLogs, monthlyRedempRequest, customerInvestment);
					redemptionDto.setSuccess(true);
					redemptionDto.setResulteMsg("SUCCESS");
				}
			}
		} else {
			redemptionDto.setSuccess(false);
			redemptionDto.setResulteMsg("This Process Can't complite,</br> Please Check Customer Unit Balance");
			return;
		}

	}

	private List<CustomerTransactionLog> createLogs(List<RedemptionReqToRedemtion> redemptionReqToRedemtions, CustomerRedemptionRequest customerRedemptionRequest) {
		List<CustomerTransactionLog> customerTransactionLogs = new ArrayList<CustomerTransactionLog>();
		for (RedemptionReqToRedemtion redemptionReqToRedemtion : redemptionReqToRedemtions) {
			CustomerTransactionLog customerTransactionLog = new CustomerTransactionLog();
			customerTransactionLog.setCustomer(customerRedemptionRequest.getCustomer());
			customerTransactionLog.setFund(customerRedemptionRequest.getFund());
			customerTransactionLog.setTranType("REDEMPTION");
			customerTransactionLog.setTranUnits(redemptionReqToRedemtion.getReleaseUnits().negate());
			customerTransactionLog.setCustomerInvestment(redemptionReqToRedemtion.getCustomerInvestment());
			customerTransactionLog.setUser(LoginAction.getCurrentLogingUser());
			customerTransactionLogs.add(customerTransactionLog);

		}
		return customerTransactionLogs;
	}

	private List<CustomerInvestment> checkInvestmentBalance(List<RedemptionReqToRedemtion> redemtion) {

		List<CustomerInvestment> customerInvestments = new ArrayList<CustomerInvestment>();
		for (RedemptionReqToRedemtion redemptionReqToRedemtion : redemtion) {
			CustomerInvestment investment = redemptionReqToRedemtion.getCustomerInvestment();
			BigDecimal balance = investment.getBalanceUnits().subtract(redemptionReqToRedemtion.getReleaseUnits());
			if (balance.compareTo(BigDecimal.ZERO) >= 0) {
				investment.setBalanceUnits(balance);
				customerInvestments.add(investment);
			} else {
				customerInvestments.removeAll(customerInvestments);
				break;
			}
		}
		return customerInvestments;
	}

	public void update(RedemptionDto redemptionDto, String redemDetails, int redemption_id) {

		CustomerRedemptionRequest requesRedemptionRequest = daoImpl.getById(redemption_id);
		if (redemptionDto.getTotAmount() != null) {
			String amount = redemptionDto.getTotAmount().replaceAll(",", "");
			double da = Double.parseDouble(amount);
			requesRedemptionRequest.setTotAmount(BigDecimal.valueOf(da));
		}
		if (redemptionDto.getTotUnit() != null) {
			String amount = redemptionDto.getTotUnit().replaceAll(",", "");
			double du = Double.parseDouble(amount);
			requesRedemptionRequest.setTotUnit(BigDecimal.valueOf(du));
		}
		if (redemptionDto.getUnitprice() != null) {
			String amount = redemptionDto.getUnitprice().replaceAll(",", "");
			double du = Double.parseDouble(amount);
			requesRedemptionRequest.setRedemUnitPrice(BigDecimal.valueOf(du));
		}

		List<RedemptionReqToRedemtion> redemptList = new ArrayList<RedemptionReqToRedemtion>();
		if (redemDetails != null) {
			redemDetails = "{ \"redemDetails\" : ".concat(redemDetails) + " }";
			try {
				JSONObject jsonObject = new JSONObject(redemDetails);
				JSONArray jArray = jsonObject.getJSONArray("redemDetails");
				for (int i = 0; i < jArray.length(); i++) {
					JSONObject jObj = jArray.getJSONObject(i);
					RedemptionReqToRedemtion redemtion = new RedemptionReqToRedemtion();
					redemtion.setCustomerInvestment(investmentDaoImpl.getById(jObj.getInt("investmentId")));
					redemtion.setCustomerRedemptionRequest(requesRedemptionRequest);
					redemtion.setBalance(BigDecimal.ZERO);
					redemtion.setReleaseAmount(BigDecimal.valueOf(jObj.getDouble("releaseAmount")));
					redemtion.setReleaseUnits(BigDecimal.valueOf(jObj.getDouble("releaseUnits")));
					redemptList.add(redemtion);
				}
			} catch (JSONException e) {
				e.printStackTrace();
			}
		}

		requesRedemptionRequest.setRedemptionReqToRedemtions(redemptList);

		Object object = daoImpl.updateRedemtioRequest(requesRedemptionRequest);
		redemptionDto.setSuccess(true);
		redemptionDto.setResulteMsg("SUCCESS");

	}

	public CustomerRedemptionRequest createNextMonthlyRedemtioReqest(CustomerInvestment perInvestment) {

		Sequence seq = new Sequence();
		CustomerRedemptionRequest request = new CustomerRedemptionRequest();
		List<RedemptionReqToRedemtion> redemtions = new ArrayList<RedemptionReqToRedemtion>();

		request.setCustomer(perInvestment.getCustomer());
		request.setRedemptionCode("RED" + seq.getNextValue("REDEMPTION"));
		request.setRedemptionType("V");

		request.setTotUnit(BigDecimal.ZERO);
		request.setTotAmount(BigDecimal.ZERO);
		request.setRequestDate(perInvestment.getRequestDate());
		request.setRedemUnitPrice(BigDecimal.ZERO);
		request.setExpectedDate(perInvestment.getMonIntNextDate());
		request.setStatus("INITIAL");
		request.setFund(perInvestment.getFund());
		request.setRecordUser(LoginAction.getCurrentLogingUser().getId());
		request.setRecordDate(new Date());
		request.setRecordType("M");

		RedemptionReqToRedemtion redemtion = new RedemptionReqToRedemtion();
		redemtion.setCustomerRedemptionRequest(request);
		redemtion.setReleaseUnits(BigDecimal.ZERO);
		redemtion.setReleaseAmount(BigDecimal.ZERO);
		redemtion.setBalance(BigDecimal.ZERO);
		redemtion.setCustomerInvestment(perInvestment);
		redemtions.add(redemtion);

		request.setRedemptionReqToRedemtions(redemtions);
		return request;
	}

	public List<RedemptionDto> getConfirmedRedemptions() {

		List<RedemptionDto> dtos = new ArrayList<RedemptionDto>();
		List<CustomerRedemptionRequest> requests = daoImpl.getConfirmedRedemptionRequest();

		for (CustomerRedemptionRequest customerRedemptionRequest : requests) {
			RedemptionDto dto = new RedemptionDto();
			dto.setId(customerRedemptionRequest.getId());
			dto.setCustomer(customerRedemptionRequest.getCustomer().getId());
			dto.setCustomerCode(customerRedemptionRequest.getCustomer().getCode());
			dto.setCustomer_name(customerRedemptionRequest.getCustomer().getDenotedByInitials() + " " + customerRedemptionRequest.getCustomer().getSurname());
			dto.setRedemptionCode(customerRedemptionRequest.getRedemptionCode());
			dto.setRedemptionType(customerRedemptionRequest.getRedemptionType());
			if (customerRedemptionRequest.getRequestDate() != null)
				dto.setRequestDate(format.format(customerRedemptionRequest.getRequestDate()));
			dto.setStatus(customerRedemptionRequest.getStatus());
			if (customerRedemptionRequest.getExpectedDate() != null)
				dto.setExpectedDate(format.format(customerRedemptionRequest.getExpectedDate()));
			dto.setFund_id(customerRedemptionRequest.getFund().getId());
			if (customerRedemptionRequest.getTotAmount() != null)
				dto.setTotAmount(customerRedemptionRequest.getTotAmount().toString());
			if (customerRedemptionRequest.getTotUnit() != null)
				dto.setTotUnit(customerRedemptionRequest.getTotUnit().toString());
			if (customerRedemptionRequest.getConfirmDate() != null)
				dto.setConfirmDate(format.format(customerRedemptionRequest.getConfirmDate()));
			dto.setRecordUser(customerRedemptionRequest.getRecordUser());
			if (customerRedemptionRequest.getStatus().equals("CONFIRM")) {
				dto.setUnitprice(customerRedemptionRequest.getRedemUnitPrice().toString());
			}
			dto.setRecordType(customerRedemptionRequest.getRecordType());
			dtos.add(dto);
		}
		return dtos;

	}

	public void cancelConfRedemtion(RedemptionDto redemptionDto, int redemption_id) {
		if (redemption_id != 0) {
			CustomerRedemptionRequest customerRedemptionRequest = daoImpl.getById(redemption_id);
			if (customerRedemptionRequest != null) {
				customerRedemptionRequest.setStatus("CANCEL");

				List<MoneyTransaction> transactions = moneyTransactionModel.getRedemptionReversTranasactions(customerRedemptionRequest);
				List<CustomerTransactionLog> customerTransactionLogs = createLogsRev(customerRedemptionRequest.getRedemptionReqToRedemtions(), customerRedemptionRequest);
				daoImpl.cancelRedemption(customerRedemptionRequest, transactions, customerTransactionLogs);
				redemptionDto.setSuccess(true);
				redemptionDto.setResulteMsg("Success");
			}
		}
	}

	private List<CustomerTransactionLog> createLogsRev(List<RedemptionReqToRedemtion> redemptionReqToRedemtions, CustomerRedemptionRequest customerRedemptionRequest) {
		List<CustomerTransactionLog> customerTransactionLogs = new ArrayList<CustomerTransactionLog>();
		for (RedemptionReqToRedemtion redemptionReqToRedemtion : redemptionReqToRedemtions) {
			CustomerTransactionLog customerTransactionLog = new CustomerTransactionLog();
			customerTransactionLog.setCustomer(customerRedemptionRequest.getCustomer());
			customerTransactionLog.setFund(customerRedemptionRequest.getFund());
			customerTransactionLog.setTranType("REDEMPTION");
			customerTransactionLog.setTranUnits(redemptionReqToRedemtion.getReleaseUnits());
			customerTransactionLog.setCustomerInvestment(redemptionReqToRedemtion.getCustomerInvestment());
			customerTransactionLog.setUser(LoginAction.getCurrentLogingUser());
			customerTransactionLogs.add(customerTransactionLog);

		}
		return customerTransactionLogs;
	}

	public List<SummaryDetailDto> getSummaryDetails(int customer_id, int invest_fund_id) {

		List<SummaryDetailDto> detailDtos = new ArrayList<SummaryDetailDto>();

		List<CustomerRedemptionRequest> redemptionRequests = daoImpl.getRedemption(customer_id, invest_fund_id);
		for (CustomerRedemptionRequest customerRedemptionRequest : redemptionRequests) {
			for (RedemptionReqToRedemtion redemtion : customerRedemptionRequest.getRedemptionReqToRedemtions()) {
				SummaryDetailDto detailDto = new SummaryDetailDto();
				detailDto.setAmount(redemtion.getReleaseAmount().toString());
				detailDto.setDate(format.format(customerRedemptionRequest.getRecordDate()));
				detailDto.setInvenstmentCode(redemtion.getCustomerInvestment().getInvenstmentCode());
				detailDto.setNoOfUnits(redemtion.getReleaseUnits().toString());
				detailDto.setStatus("INITIAL");
				detailDto.setSummaryType("REDEMPTION");
				detailDtos.add(detailDto);
			}
		}

		List<CustomerPledge> customerPledges = pledgeDaoImpl.getPledge(invest_fund_id, customer_id);
		for (CustomerPledge customerPledge : customerPledges) {
			SummaryDetailDto detailDto = new SummaryDetailDto();
			detailDto.setAmount(customerPledge.getPledgeUnits().toString());
			detailDto.setDate(format.format(customerPledge.getRecordDate()));
			detailDto.setInvenstmentCode(customerPledge.getCustomerInvestment().getInvenstmentCode());
			detailDto.setNoOfUnits(customerPledge.getPledgeUnits().toString());
			detailDto.setStatus(customerPledge.getStatus());
			detailDto.setSummaryType("PLEDGE");
			detailDtos.add(detailDto);
		}
		for (int i = 0; i < detailDtos.size(); i++) {
			detailDtos.get(i).setId(i);
		}

		return detailDtos;
	}
}
